//
//  D_UserBarViewController.m
//  音悦咖
//
//  Created by dllo on 15/5/1.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "D_UserBarViewController.h"
#import "LoginViewController.h"
#import "UIImageView+WebCache.h"
#import "UMSocial.h"
@interface D_UserBarViewController ()

@property (nonatomic, retain)  UIImageView *headImg;
@property (nonatomic, retain) UILabel *lable;
@property (nonatomic, retain) UILabel *outLable;
@property (nonatomic, retain) UIView *view1;

@end

@implementation D_UserBarViewController


- (void)dealloc
{
    [super dealloc];
}

#pragma mark - 通知中心
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // 通知的注册一般放在初始化中
        [self creatNotificationCenter];
    }
    return self;
}

- (void)creatNotificationCenter
{
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    
    [center addObserver:self selector:@selector(chuangValue:) name:@"value" object:nil];
}

- (void)chuangValue:(NSNotification *)noti
{

    [self.headImg setImageWithURL:[NSURL URLWithString:[noti.userInfo objectForKey:@"url"]] placeholderImage:[UIImage imageNamed:@"loginhh"]];
    [self.headImg setClipsToBounds:YES];
     self.lable.text = [noti.userInfo objectForKey:@"name"];
    if (![[noti.userInfo objectForKey:@"url"] isEqualToString:@""]) {
        //注销
        self.outLable = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * 0.7, 10, SCREEN_HEIGHT * 0.3, SCREEN_WIDTH * 0.08)];
        self.outLable.userInteractionEnabled = YES;
        self.outLable.text = @"注销";
        self.outLable.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
        self.outLable.textColor = [UIColor blueColor];
        [self.view1 addSubview:self.outLable];
        
        UITapGestureRecognizer *outTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(outTap)];
        [self.outLable addGestureRecognizer:outTap];
        [outTap release];
        [_outLable release];
    }
    
}
// 注销方法
- (void)outTap
{
    [[UMSocialDataService defaultDataService] requestUnOauthWithType:UMShareToSina  completion:^(UMSocialResponseEntity *response){
        NSLog(@"response is %@",response);
    }];
    self.headImg.image = [UIImage imageNamed:@"loginhh"];
    self.lable.text = @"注册/登录";
    self.outLable.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor clearColor];
 
    
    // 登陆
     self.view1 = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * 0.02667, SCREEN_WIDTH * 0.02667, SCREEN_WIDTH - SCREEN_HEIGHT * 0.03, SCREEN_HEIGHT / 5 + SCREEN_WIDTH * 0.07)];
    self.view1.backgroundColor = [UIColor grayColor];
    [self.view1.layer setCornerRadius:10];
    self.view1.alpha = 0.6;
    // 登陆图片
    self.headImg = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH *0.373, SCREEN_HEIGHT * 0.045, SCREEN_HEIGHT * 0.09, SCREEN_HEIGHT * 0.09)];
    self.headImg.image = [UIImage imageNamed:@"lloo"];
    [self.headImg setClipsToBounds:YES];
    
    self.headImg.userInteractionEnabled = YES;
    UITapGestureRecognizer *logImg = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(loginAction)];
    [self.headImg addGestureRecognizer:logImg];
    [logImg release];
    
    [self.view1 addSubview:self.headImg];
    // 登陆lable
    self.lable = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * 0.347, SCREEN_HEIGHT * 0.09 + SCREEN_HEIGHT * 0.06, SCREEN_HEIGHT * 0.3, SCREEN_WIDTH * 0.08)];
    self.lable.text = @"音悦咖";
    self.lable.textColor = [UIColor whiteColor];
    self.lable.font = [UIFont fontWithName:@"Helvetica-Bold" size:23];
    self.lable.userInteractionEnabled = YES;
    
    // 登陆手势
//    UITapGestureRecognizer *logTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(loginAction)];
//    [self.lable addGestureRecognizer:logTap];

    //    [logTap release];
    
    [self.view1 addSubview:self.lable];
    [self.view addSubview:self.view1];
    
    [_headImg release];
    [self.lable release];
    [self.view1 release];
    
    // 本地歌曲
    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * 0.02667,  SCREEN_HEIGHT / 5 + SCREEN_HEIGHT * 0.03 + SCREEN_WIDTH * 0.05 * 2, SCREEN_WIDTH - SCREEN_HEIGHT * 0.03, SCREEN_HEIGHT * 0.09)];
    view2.backgroundColor = [UIColor grayColor];
    [view2.layer setCornerRadius:10];
    view2.alpha = 0.7;
    view2.userInteractionEnabled = YES;
    UIImageView *img1 = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * 0.02667, SCREEN_WIDTH * 0.02667, SCREEN_WIDTH * 0.08, SCREEN_WIDTH * 0.08)];
    img1.image = [UIImage imageNamed:@"bendi"];
    [view2 addSubview:img1];
    UIImageView *img2 = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH / 1.3, SCREEN_WIDTH * 0.02667, SCREEN_WIDTH * 0.08, SCREEN_WIDTH * 0.08)];
    img2.image = [UIImage imageNamed:@"bofang"];
    [view2 addSubview:img2];
    
    UILabel *local = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_HEIGHT * 0.09, SCREEN_WIDTH * 0.02667, SCREEN_WIDTH * 0.2667, SCREEN_WIDTH * 0.08)];
    local.text = @"本地歌曲";
    local.textColor = [UIColor whiteColor];
    [view2 addSubview:local];
    
    UITapGestureRecognizer *localTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(localTapAction)];
    [view2 addGestureRecognizer:localTap];
    
    [self.view addSubview:view2];
    [local release];
    [img1 release];
    [img2 release];
    [view2 release];
    [localTap release];
    
    
    // 最近播放
    UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * 0.02667, SCREEN_HEIGHT / 5 + SCREEN_HEIGHT * 0.12 + SCREEN_WIDTH * 0.04* 3 , SCREEN_WIDTH - SCREEN_HEIGHT * 0.03, SCREEN_HEIGHT * 0.09)];
    view3.backgroundColor = [UIColor grayColor];
    [view3.layer setCornerRadius:10];
    view3.alpha = 0.7;
    
    UIImageView *img3 = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * 0.02667, SCREEN_WIDTH * 0.02667, SCREEN_WIDTH * 0.08, SCREEN_WIDTH * 0.08)];
    img3.image = [UIImage imageNamed:@"zuijin"];
    [view3 addSubview:img3];
    
    UILabel *lable3 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_HEIGHT * 0.09, SCREEN_WIDTH * 0.02667, SCREEN_WIDTH * 0.2667, SCREEN_WIDTH * 0.08)];
    lable3.text = @"最近播放";
    lable3.textColor = [UIColor whiteColor];
    [view3 addSubview:lable3];
    [self.view addSubview:view3];
    
    UITapGestureRecognizer *playAction = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(playAction)];
    [view3 addGestureRecognizer:playAction];
    
    [lable3 release];
    [img3 release];
    [view3 release];
    [playAction release];
    // 我喜欢
    UIView *view4 = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * 0.02667, SCREEN_HEIGHT / 5 + SCREEN_HEIGHT * 0.21 + SCREEN_WIDTH * 0.04 * 4 , SCREEN_WIDTH - SCREEN_HEIGHT * 0.03, SCREEN_HEIGHT * 0.09)];
    view4.backgroundColor = [UIColor grayColor];
    [view4.layer setCornerRadius:10];
    view4.alpha = 0.7;
    
    UIImageView *img4 = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * 0.02667, SCREEN_WIDTH * 0.02667, SCREEN_WIDTH * 0.08, SCREEN_WIDTH * 0.08)];
    img4.image = [UIImage imageNamed:@"woxihuan"];
    [view4 addSubview:img4];
    
    UILabel *lable4 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_HEIGHT * 0.09, SCREEN_WIDTH * 0.02667, SCREEN_WIDTH * 0.2667, SCREEN_WIDTH * 0.08)];
    lable4.text = @"我喜欢";
    lable4.textColor = [UIColor whiteColor];
    [view4 addSubview:lable4];
    
    UITapGestureRecognizer *myLove = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(myLoveAction)];
    [view4 addGestureRecognizer:myLove];
    
    [self.view addSubview:view4];
    [img4 release];
    [lable4 release];
    [view4 release];
    // 我的收藏
    UIView *view5 = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * 0.02667, SCREEN_HEIGHT / 5 + SCREEN_HEIGHT * 0.3 + SCREEN_WIDTH * 0.04 * 5 , SCREEN_WIDTH - SCREEN_HEIGHT * 0.03, SCREEN_HEIGHT * 0.09)];
    view5.backgroundColor = [UIColor grayColor];
    [view5.layer setCornerRadius:10];
    view5.alpha = 0.7;
    
    UIImageView *img5 = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * 0.02667, SCREEN_WIDTH * 0.02667, SCREEN_WIDTH * 0.08, SCREEN_WIDTH * 0.08)];
    img5.image = [UIImage imageNamed:@"shoucang"];
    [view5 addSubview:img5];
    
    UILabel *lable5 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_HEIGHT * 0.09, SCREEN_WIDTH * 0.02667, SCREEN_WIDTH * 0.2667, SCREEN_WIDTH * 0.08)];
    lable5.text = @"我的收藏";
    lable5.textColor = [UIColor whiteColor];
    [view5 addSubview:lable5];
    
    UITapGestureRecognizer *downLoad = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(downLoadAction)];
    [view5 addGestureRecognizer:downLoad];
    
    [self.view addSubview:view5];
    [img5 release];
    [lable5 release];
    [view5 release];
   
}

// 登陆方法
- (void)loginAction
{
//    [self.delegate D_UserBarViewControllerPushViewController:@"0"];
    
//    [UIView animateWithDuration:2 animations:^{
//      
////        self.headImg.frame = CGRectMake(80, 40, 200, 200);
//        self.headImg.center = CGPointMake(100, 100);
//        
//        self.headImg.alpha = 0.00001;
//        
//    } completion:^(BOOL finished) {
//        self.headImg.frame = CGRectMake(SCREEN_WIDTH *0.373, SCREEN_HEIGHT * 0.045, SCREEN_HEIGHT * 0.09, SCREEN_HEIGHT * 0.09);
//        self.headImg.alpha = 1;
//    }];

    CAKeyframeAnimation *keyFrame = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    
    // 产生一条路径
    CGMutablePathRef path =  CGPathCreateMutable();
    // 设置起点
    CGPathMoveToPoint(path, NULL, self.headImg.center.x,self.headImg.center.y);
    // 保存起点
    CGPoint o = self.headImg.center;
    // 添加一个路过的点
    CGPathAddLineToPoint(path, NULL, 0, SCREEN_HEIGHT * 0.15);
    CGPathAddLineToPoint(path, NULL, SCREEN_WIDTH, SCREEN_HEIGHT * 0.3);
    CGPathAddLineToPoint(path, NULL, 0, SCREEN_HEIGHT * 0.45);
    CGPathAddLineToPoint(path, NULL, SCREEN_WIDTH, SCREEN_HEIGHT * 0.6);
    CGPathAddLineToPoint(path, NULL, 0, SCREEN_HEIGHT- 100);
    
    CGPathAddLineToPoint(path, NULL, SCREEN_WIDTH, SCREEN_HEIGHT * 0.6);
     CGPathAddLineToPoint(path, NULL, 0, SCREEN_HEIGHT * 0.45);
     CGPathAddLineToPoint(path, NULL, SCREEN_WIDTH, SCREEN_HEIGHT * 0.3);
//    CGPathAddLineToPoint(path, NULL, 0, 100);
    CGPathAddLineToPoint(path, NULL, o.x, o.y);
    // 添加曲线
//    CGPathAddCurveToPoint(path, NULL, 300, 200, 100, 100, 300, 0);
    
    // 设置路径信息
    keyFrame.path = path;
    // 设置时间
    keyFrame.duration = 6;
    // 添加到layer
    [self.headImg.layer addAnimation:keyFrame forKey:@"dd"];
    


}

// 本地歌曲
- (void)localTapAction
{
    [self.delegate D_UserBarViewControllerPushViewController:@"1"];
    
}

// 最近播放
- (void)playAction
{
    [self.delegate D_UserBarViewControllerPushViewController:@"2"];
}

// 我的收藏
- (void)myLoveAction
{
    [self.delegate D_UserBarViewControllerPushViewController:@"3"];
}

// 我的下载
- (void)downLoadAction
{
    [self.delegate D_UserBarViewControllerPushViewController:@"4"];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
